package com.edu.networkexperimentation.model.algorithm;

import com.edu.networkexperimentation.model.domain.Question;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 遗传算法中的个体
 */
@Data
public class Individual {

    // 染色体的序号
    private int id;

    // 适应度
    private double fitness;

    // 难度系数
    private double difficulty;

    // 所有的问题
    private List<Question> questions = new ArrayList<>();

    public double getDifficulty() {
        difficulty = 0;
        this.questions.forEach(item -> {
            difficulty += item.getDifficulty();
        });
        difficulty /= this.questions.size();
        return difficulty;
    }

}
